{include file="public/header"/}
<div id="container">
    <div id="page-header" class="am-cf">

        <div class="button">
            <a id="addword" class="am-btn am-btn-xs am-btn-primary" data-pjax><i class="am-icon-plus"></i> 添加问候语</a>
        </div>
    </div>
    <section class="panel" style="width: 98%;margin: 5px auto;">
     <table class="table">
            <tr>
                <th>问候语</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            {volist name='lister' id='talk'}
            <tr>
                <td>{$talk.content}</td>
                {if $talk.state == 'using'}
                <td>
                    <laber class="am-btn-primary ">默认使用</laber>
                </td>
                {else}
                <td><i class="am-btn-defulat">暂不使用</i></td>
                {/if}
                <td>
                    <a href='javascript:setdefalut({$talk.sid})' class='am-badge am-badge-primary'><i
                            class='am-icon-edit'></i> 设置默认</a><a href='javascript:tdelete({$talk.sid})'
                                                                 class='am-badge am-badge-danger'> <i
                        class='am-icon-recycle'></i> 删除</a>
                </td>
            </tr>
            {/volist}

        </table>
        {$page}
  </section>


</div>


<script type="text/javascript">

    $("#addword").on("click", function () {
        var str = '';
        str += '<form  class="layui-form" style="margin-top:23px;" >';
        str += '<div class="layui-form-item layui-form-text">';
        str += '<div class="layui-input-block" style="margin-left:20px;"><textarea id="talks" placeholder="请输入内容" class="layui-textarea" style="width:360px;"></textarea></div></div>';
        str += '</from>';


        layer.open({
            title: '添加问候语',
            type: 1,
            area: ['400px', '230px'],
            content: str,
            btn: ['提交', '关闭'],
            yes: function () {
                $.ajax({
                    url: "/admin/manager/cmtalk",
                    type: "post",
                    data: {content: $("#talks").val()},
                    success: function (res) {
                        if (res.code ==0) {
                            layer.msg(res.msg, {icon: 1,time:2000,end:function () {
                                location.reload();
                            }});
                          
                        }

                    }
                })
            }
        });
    });


    function setdefalut(id) {
        $.ajax({
            url: '/admin/set/settalkdefa',
            type: 'post',
            data: {tid: id},
            success: function (res) {
                if (res.code == 0) {
                    if(res.data){
                         layer.msg('设置成功', {icon: 1,time:2000,end:function () {
                            location.reload();
                        }});
                    }
                  
                }
            }
        });
    }


    function tdelete(id) {
        $.ajax({
            url: '/admin/set/tdelete',
            type: 'post',
            data: {tid: id},
            success: function (res) {
                if (res.code == 0) {
                    if(res.data){
                      layer.msg('删除成功',{time:2000,end:function () {
                        location.reload();
                      }});
                    }
                }
            }
        });
    }

</script>

{include file="public/footer"/}
